package com.framework;

// ===== 配置管理 =====

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

class ConfigManager {
    // 加载工作流配置
    public BusinessWorkflow loadWorkflow(String id) {
        BusinessWorkflow workflow = new BusinessWorkflow();
        workflow.setId("user-registration");
        workflow.setName("用户注册流程");

        // 步骤1: 用户验证
        BusinessWorkflow.WorkflowStep step1 = new BusinessWorkflow.WorkflowStep();
        step1.setComponent( "ValidationComponent");;
        step1.setConditions(List.of("SUCCESS"));
        workflow.getSteps().add(step1);

        // 步骤2: 保存用户
        BusinessWorkflow.WorkflowStep step2 = new BusinessWorkflow.WorkflowStep();
        step2.setComponent( "EnhancedUserService");;
        step2.setOutputMappings(Map.of("userId", "userId"));
        workflow.getSteps().add(step2);

        // 步骤3: 保存文件
        // BusinessWorkflow.WorkflowStep step3 = new BusinessWorkflow.WorkflowStep();
        // step3.setComponent( "FileService");
        // step3.setInputMappings( Map.of("input", "profileImage"));
        // step3.setOutputMappings(Map.of("storedPath", "profilePath"));
        // workflow.getSteps().add(step3);

        // 步骤4: 发送邮件
        // BusinessWorkflow.WorkflowStep step4 = new BusinessWorkflow.WorkflowStep();
        // step4.setComponent( "EmailService");
        // step4.setInputMappings(Map.of("recipient", "email", "userId", "userId"));
        // workflow.getSteps().add(step4);

        return workflow;
    }
    // 加载校验规则
    public Map<String, List<ValidationRule>> loadValidationRules(String id) {
        Map<String, List<ValidationRule>> rules = new HashMap<>();

        // 用户注册规则
        List<ValidationRule> userRules = Arrays.asList(
                new RequiredRule("username"),
                new LengthRule("password", 8, 30),
                new RegexRule("email", "^\\S+@\\S+\\.\\S+$","邮件格式不正确")
        );
        rules.put("user-registration", userRules);

        return rules;
    }
}